<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>cacheCheck</title>
<!-- Bootstrap core CSS -->
<link href="../../asserts/bootstrap-3.3.0/css/bootstrap.min.css" rel="stylesheet">
<!--lib js  -->
<script type="text/javascript" src="../../asserts/jquery-1.11.3/jquery.min.js"></script>
<!-- js加载器 -->
<script type="text/javascript" src="../../src/core/jui.config.js"></script>
<script type="text/javascript" src="../../src/loader/loader.js"></script>
<script type="text/javascript" src="gridData.js"></script>

</head>
<body>

<h3>本功能可记住勾选状态,如:在第一页勾选后,点击下一页再返回到第一页依然勾选</h3>
<button onclick="getChecked()">getChecked()</button>
<button onclick="checkAll()">checkAll</button>
<button onclick="uncheckAll()">uncheckAll()</button>
<button onclick="checkRow(2)">checkRow(2)</button>
<button onclick="uncheckRow(2)">uncheckRow(2)</button>
<button onclick="selectRecord(26)">selectRecord(26)</button>
<hr>
<div id="grid"></div>

<script type="text/javascript">

JUI
.dir('../../src/') // 设置JS存放根目录
.use('Grid',function(){
	grid = new JUI.Grid({
		renderId:'grid'
		,data : gridData
		,striped:true // 斑马线
		,pagination :true
		,selectCache :true // 勾选记忆
		// 添加事件方式1
		,onCheck :function(e) {
			console.log('onCheck index:' + e.index + ' mobile:' + e.row.mobile)
		}
		,onCheckAll:function(e) {
			console.log('onCheckAll rows len:' + e.rows.length)
		}
		,onUncheckAll:function(e) {
			console.log('onUncheckAll rows len:' + e.rows.length)
		}
		,columns : [ [
			{field:'orderId',checkbox : true} // 勾选
			,{
				field : 'cityName',
				title : '城市'
			},
			{
				field : 'mobile',
				title : '手机号'
			},
			{
				field : 'address',
				title : '地址'
			},
			{
				field : 'createDate',
				title : '创建时间'
			}] 
		]
	});
	
	// 添加事件方式2
	grid.on('Uncheck',function(e){
		console.log('onUnCheck index:' + e.index + ' mobile:' + e.row.mobile)
	})
});

function uncheckAll(){
	grid.uncheckAll();
}

function checkAll(){
	grid.checkAll();
}

function checkRow(i){
	grid.checkRow(i);
}

function uncheckRow(i){
	grid.uncheckRow(i);
}

function selectRecord(val){
	grid.selectRecord(val);
}

function getChecked(){
	var datas = grid.getChecked();
	console.log(datas);
}
</script>
</body>
</html>